<?php 
    sleep(1);
    require_once ("connect.php"); 
    $file = $_FILES['fileimg'];
    $fileName = $file['name'];
    $fileSize = $file['size'];
    if (!$fileSize) {
        $fileSize = $_SERVER['CONTENT_LENGTH'];
    }

    $name = $_POST['product_name'];
    $price = $_POST['product_price'];
    $weight = $_POST['product_weight'];
    $cate = $_POST['cate_product'];

    $fileName .= $name;

    $sql = "INSERT INTO products(products.product_name,products.price,products.weight,products.cate_id,products.img)
            VALUES(?,?,?,?,?)";
    $statement = $db->prepare($sql);
    $data = array($name,$price,$weight,$cate,$fileName);
    

    try {
        $statement->execute($data);
        echo json_encode(array(
            "success" => true,
            "fileName" => $fileName,
            "fileSize" => $fileSize
        ));
    } catch (Exception $e) {
        echo json_encode(array(
            "success" => false,
            "fileName" => $fileName,
            "fileSize" => $fileSize
        ));
    }


?>